<template>
    <div class="cont mb-4">
        <CustomQuery @submit="changeQuery" :form-columns="queryList"></CustomQuery>
    </div>
    <div class="cont">
        <CustomTable selection :columns="columns" :data-source="data">
            <template #table-left-nav>
                <a-button @click="useGo" type="primary" :icon="h(PlusOutlined)">新增计划规则</a-button>
            </template>
            <template #column-action="{ record }">
                <a-switch v-model:checked="record.checked" />
            </template>
        </CustomTable>
    </div>
</template>

<script setup lang="ts">
import { PlusOutlined } from '@ant-design/icons-vue';
import { h } from 'vue'

import CustomTable from '@/components/customTable/CustomTable.vue';
import CustomQuery from '@/components/customQuery/CustomQuery.vue';
import { CustomQueryColumns, CustomQueryValue } from '@/components/customQuery/types';
import { CustomTableColumns, CUstomTableData } from '@/components/customTable/types';

const router = useRouter()
const useGo = () => {
    router.push('/operationManagement/planingRules/add')
}

const queryList = reactive<CustomQueryColumns[]>([
    { label: '规则名称', key: 'rules', type: 'input' },
])

const changeQuery = (queryState: CustomQueryValue) => {
    alert('查询结果为' + JSON.stringify(queryState))
}

const data = ref<CUstomTableData[]>([])
const columns = reactive<CustomTableColumns[]>([
    {
        title: "规则名称",
        dataIndex: "rules",
        key: "rules",
    },
    
    {
        title: "距离规则",
        dataIndex: "distanceRule",
        key: "distanceRule",
    },
    
    {
        title: "重量规则",
        dataIndex: "weightRules",
        key: "weightRules",
    },
    
    {
        title: "时间规则",
        dataIndex: "timeRule",
        key: "timeRule",
    },
    
    {
        title: "时间",
        dataIndex: "time",
        key: "time",
    },
    {
        flag: 'ACTION'
    },
]);


onMounted(() => {
    for (let i = 0; i < 100; i++) {
        data.value.push(
            {rules: '规则名称',distanceRule: '距离规则',weightRules: '重量规则',timeRule: '时间规则',time: '时间',checked: true}
        )
    }
})
</script>

<style scoped></style>